package gql

import (
	"gitee.com/gopher2011/graph-ql-demo/mapper"
	"github.com/graphql-go/graphql"
)

// Resolver struct holds a connection to our database
type Resolver struct {
	db *mapper.Db
}

// UserResolver resolves our user query through a db call to GetUserByName
// Resolver 就是通过取得在Args中定义的入参，调用了mapper的方法，真正查询了数据库，并返回数据
func (r *Resolver) UserResolver(p graphql.ResolveParams) (interface{}, error) {
	// Strip the name from arguments and assert that it's a string
	name, ok := p.Args["name"].(string)
	if ok {
		users := r.db.GetUsersByName(name)
		return users, nil
	}
	return nil, nil
}
